public without sharing class SalesYszxdetailsHandler {

    public static void match(List< SalesYszxdetails__c> list_new){
        ///获取销售明细
        Set<String> accodes = new Set<String>();
        Set<String> procodes = new Set<String>();
        for(SalesYszxdetails__c s: list_new){
        
		 accodes.add(s.pk_cubasdoc__c);
         procodes.add(s.pk_invbasdoc__c);   
        }
        ///获取NC客商对应的客户
        Map<String,Id>acMap = new Map<String, Id>();
        for(Account a :[select Id,NCICCode__c from Account where NCICCode__c in: accodes]){
             if(!acMap.containsKey(a.NCICCode__c)){
             	acMap.put(a.NCICCode__c,a.Id);
             }
        }

        
        //存货匹配
          Map<String,Id>prMap = new Map<String, Id>();
        for(Product__c p :[select Id,pk_invbasdoc__c from Product__c where pk_invbasdoc__c in: procodes]){
             if(!prMap.containsKey(p.pk_invbasdoc__c)){
             	prMap.put(p.pk_invbasdoc__c,p.Id);
             }
        }
        
          
          //用客商pk匹配客户 用存货pk 匹配产品
        for(SalesYszxdetails__c s : list_new){
            System.debug('***' + s);
        	if(acMap.containsKey(s.pk_cubasdoc__c)){
            	s.RelateAccount__c = acMap.get(s.pk_cubasdoc__c);
            }else{
            	//s.RelateAccount__c = null;
            }
            if(prMap.containsKey(s.pk_invbasdoc__c)){
            	s.RelateProduct__c = prMap.get(s.pk_invbasdoc__c);
            }else{
            	//s.RelateProduct__c = null;
            }
           
        }
        
        
    }
}